﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BYS.AAPT.Common;
using System.Net;

namespace BYS.XiAnComDept.App
{
    public static class UriExtension
    {
        public static Dictionary<string, string> GetQuery(this Uri uri)
        {
            Dictionary<string, string> result = new Dictionary<string, string>();
            string strUri = uri.ToString();
            int index = strUri.IndexOf('?');
            if (index > 0)
            {
                strUri = strUri.Right(strUri.Length - index - 1);
                string[] pairs = strUri.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string pair in pairs)
                {
                    string[] keyAndValue = pair.Split(new char[] { '=' });
                    if (keyAndValue.Length == 2)
                    {
                        result.Add(keyAndValue[0], keyAndValue[1]);
                    }
                }
            }

            return result;
        }
    }
}
